﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CharacterSystem : SystemBase {


    private Dictionary<int, CharacterObj> characterLeftDic;
    private Dictionary<int, CharacterObj> characterRightDic;
    private CharacterModel characterModel;

    private CharacterObj leftcharacterObj = new CharacterObj();
    private CharacterObj rightcharacterObj = new CharacterObj();

    public CharacterSystem(LBattleFacade battleFacade) : base(battleFacade)
    {
    
    }

    public CharacterObj getLeftCharacter()
    {
        return leftcharacterObj;
    }
    public CharacterObj getRightCharacter()
    {
        return rightcharacterObj;
    }


    public override void Init()
    {

        //characterLeftDic = new Dictionary<int, CharacterObj>();
        //characterRightDic = new Dictionary<int, CharacterObj>();

        //服务器下发的CharacterModel 
        //角色生成     setData(characterData)
        characterModel = (CharacterModel) ModelManager.Instance.GetModel<CharacterModel>();
        //============第二种逻辑
        leftcharacterObj = new CharacterObj();
        rightcharacterObj = new CharacterObj();

        //获取每一个形象放到同一个父结点上
        leftcharacterObj.SetData(characterModel.leftHero); //characterModel.GetCharacterDataByID(characterModel.leftParticipationList[i])
        //左侧团体形象中的每一个角色模型的添加
        leftcharacterObj.CreatHeroGrid(characterModel.leftParticipationList);
        //leftcharacterObj.Init();
        leftcharacterObj.OnCreat();//添加技能的组件

        // characterLeftDic.Add(characterObj.characterData.ID, characterObj);


        //获取每一个形象放到同一个父结点上
        rightcharacterObj.SetData(characterModel.rightHero); //characterModel.GetCharacterDataByID(characterModel.leftParticipationList[i])
        //左侧团体形象中的每一个角色模型的添加
        rightcharacterObj.CreatHeroGrid(characterModel.rightParticipationList);
        //leftcharacterObj.Init();
        rightcharacterObj.OnCreat();//添加技能的组件
        // characterLeftDic.Add(characterObj.characterData.ID, characterObj);


        //========================第二种逻辑End

        //===============第一种逻辑
        //characterModel.  Factory
        //CharacterObj characterObj;
        //for (int i = 0; i < characterModel.leftParticipationList.Count; i++)
        //{
        //    characterObj = new CharacterObj();
        //    characterObj.SetData(characterModel.GetCharacterDataByID(characterModel.leftParticipationList[i]));
        //    characterObj.Init();
        //    characterObj.OnCreat();//添加技能的组件
        //    characterLeftDic.Add(characterObj.characterData.ID, characterObj);

        //}


        //for (int i = 0; i < characterModel.rightParticipationList.Count; i++)
        //{
        //    characterObj = new CharacterObj();
        //    characterObj.SetData(characterModel.GetCharacterDataByID(characterModel.rightParticipationList[i]));
        //    characterObj.Init();
        //    characterObj.OnCreat();//添加技能的组件
        //    characterRightDic.Add(characterObj.characterData.ID, characterObj);

        //}

        //===============第一种逻辑  End


        m_BattleFacade.CreatRound();

    }

    public override void Relese()
    {
        if(leftcharacterObj!=null)
             leftcharacterObj.Release();
        if (rightcharacterObj != null)
            rightcharacterObj.Release();

        characterModel = null;
    }

    public override void Update()
    {

    }

}
